package com.blueocean_health.care.management.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.blueocean_health.care.management.common.base.string.StringUtils;
import com.blueocean_health.care.management.domain.base.SysResult;
import com.blueocean_health.care.management.domain.dto.RoleAuthDto;
import com.blueocean_health.care.management.service.RoleAuthService;

/**
* 角色授权
* @author huyanqiu
* @date 2018年3月27日 下午3:33:33
* @version 版本号：1.0
*/
@RestController
@RequestMapping("/role")
public class RoleAuthController {
	
	@Autowired
	private RoleAuthService roleAuthService;
	
	/**
	 * 获取授权信息
	 * @return
	 */
	@RequestMapping("/auth/query")
	public SysResult authQuery(@RequestBody String jsonString) {
		JSONObject jsonObject =  JSONObject.parseObject(jsonString);
		// 角色id
		Integer roleId = (Integer) jsonObject.get("roleId");
		// 组织id
		Integer orgId = (Integer) jsonObject.get("orgId");
		if (StringUtils.isEmpty(roleId)) {
			return SysResult.error("参数异常");
		}
		return roleAuthService.query(roleId, orgId);
	}
	
	/**
	 * 编辑授权信息
	 * @return
	 */
	@RequestMapping("/auth/modify")
	public SysResult authModify(@RequestBody RoleAuthDto roleAuthDto) {
		if (StringUtils.isEmpty(roleAuthDto.getId())) {
			return SysResult.error("参数非法");
		}
		if (StringUtils.isEmpty(roleAuthDto.getOrgId())) {
			return SysResult.error("参数非法");
		}
		return roleAuthService.modify(roleAuthDto);
	}
	
	/**
	 * 获取某组织下用户列表
	 * @return
	 */
	@RequestMapping("/user/list")
	public SysResult userList() {
		return roleAuthService.selectUserList();
	}

}
